package object_;

public class EqaulsExercise01 {
    public static void main(String[] args) {
        Person person = new Person("jack", 10, '男');
        Person person1 = new Person("jack", 10, '男');
        System.out.println(person.equals(person1)); // true
        System.out.println(person == person1); // false
    }
}

class Person {
    private String name;
    private int age;
    private char gender;

    public Person(String name, int age, char gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    @Override
    public boolean equals(Object obj) { // 重写equals，判断内容是否相等
        if(this == obj) {
            return true;
        }

        if(obj instanceof Person) {
            Person person = (Person)obj; // 向下转型
            return this.age == person.getAge() && this.name.equals(person.getName())
                    && this.gender == person.getGender();
        }
        //如果不是Person，则直接返回false
        return false;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }
}
